Skip to content

fix: quantile operand count survives memo sharing; Pass 1 deadline reports the planning budget - #1113

Merged
zzylol merged 2 commits into
refactor/stage-boundariesfrom
fix/m1-ratio-and-budget
Oct 30, 2026
Merged

zzylol merged 2 commits into
refactor/stage-boundariesfrom
fix/m1-ratio-and-budget

Conversation

@zzylol

@zzylol zzylol commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Milestone test phase (part of #1108). This fixes the last two failures from area C (#1111) and merges into refactor/stage-boundaries.

Why

Two failures were left. With guarantees enforced, the ratio of quantiles got no plan, a regression first seen at P3c. With a zero planning budget, the facade reported the wrong error.

What

1. fix(plan-selection): count quantile operands independently of node sharing.

  • The old engine's seed heuristic seed_dds_budgets (refinement/planner.rs) splits a query's error budget over its quantile inputs, counted as distinct nodes by pointer identity.
  • P3c (refactor: Pass 1 walks memo groups; HAVING placed per group; fusions are memo candidates (#1047 P3c, #1089) #1106) builds query roots over the memo groups' shared nodes, as intended. The ratio's two quantile_over_time(0.5, …) operands became one node, so the count fell from 3 to 2.
  • With the larger per-input budget, approximate DDSketch plans that can never meet the target entered the seed. The search then spent its whole budget rejecting them and never reached the valid all-exact plan (237.63/s).
  • quantile_operands(root) now counts a quantile as often as the most operands that read it on one path: q / q counts 2, while two parents over one quantile, such as avg's sum and count, count 1.
  • Stages 0–2 are unchanged. At P6b, at P3c and at this head they give identical memo, logical, physical and enumeration output, and the exact plan keeps its exact guarantee throughout.

2. fix(planner): report a Pass 1 deadline as the planning budget running out. In run.rs, Pass 1's Timeout maps to SelectionError::DeadlineReached, as before P7.

How

The root cause was found by logging the old engine's seed proposals at P6b, at P3c and at the head. Each fix comes with a test that fails without it.

Key code interfaces added / modified

Private quantile_operands in plan-selection's refinement/planner.rs; run.rs error mapping.

Major algorithm changes

None. This is a heuristic counting fix in today's Stage 3 engine, which #1095 replaces.

Before / After

  • Before: ratio of quantiles with guarantees enforced → no plan within 120 s. A zero budget → "candidate generation deadline exceeded".
  • After: the all-exact plan is selected. A zero budget → "planning budget".

Verification

New tests: quantile_operands_count_reads_not_shared_nodes, which builds the ratio over memo groups and checks that the operands really are shared, and quantile_operands_count_a_diamond_once.

The four previously failing tests now pass:

  • ratio_of_quantiles_no_listed_choice_is_cheaper_than_the_selected_plan
  • workload_examples_preserve_data_and_valid_materialized_views
  • milp_time_limit_is_reported
  • zero_budget_returns_no_unvalidated_plan

Full runs:

Target Passed
integration 362 (24 ignored)
devtools tests 79 + 17 + 4 + 7
logical 163 + 35
planner 11 + 81
plan-selection lib 293

fmt and clippy --workspace --all-targets -D warnings are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bqhAk7WA4MZcfbAoMw

zzylol and others added 2 commits October 30, 2026 18:38
… out

With a zero planning budget, Pass 1's sizing hits its deadline and the
facade reported it as "logical ASAP-aware optimization: candidate
generation deadline exceeded". Map PerComputationLogicalMemoCandidatesError::Timeout
to SelectionError::DeadlineReached, as before P7; other Pass 1 errors
keep LogicalASAPCandidates.

Fixes joint_search_equivalence::zero_budget_returns_no_unvalidated_plan
and stage_pipeline::milp_time_limit_is_reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bqhAk7WA4MZcfbAoMw
…aring

The feasibility seed's DDSketch budget splits a query's relative error
over its quantile inputs. It counted distinct quantile nodes by Rc
identity. Since P3c (#1106) Pass 1 builds each query's root over the memo
groups' nodes, so the two `quantile 0.5` operands of
`avg by (job) (q0.5 / q0.5 + q0.9)` are one shared node: the count fell
from 3 to 2, the seed admitted sketches sized for half the budget, whose
outputs have no accuracy guarantee, and the search spent its whole budget
cutting such plans one by one without reaching the exact plan.

quantile_operands counts each quantile aggregate as often as the most
operands that read it from one path (q / q reads q twice), and a diamond
of different parents over one aggregate (an average's sum and count) once,
so the count no longer depends on how equal nodes are shared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bqhAk7WA4MZcfbAoMw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working testing Corpus, regression, differential, or benchmark tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant